<?php
global $wp_version;

// Get the page number
function dmm_get_page_number() {
  if ( get_query_var( 'paged' ) ) {
    print ' | ' . __( 'Page ' , 'desk-mess-mirrored' ) . get_query_var( 'paged' );
  }
}
// end get_page_number

// Start Register Widgets
if ( function_exists( 'register_sidebar' ) )
  register_sidebars( 3,array(
                             'description' => '',
                             'before_widget' => '<li id="%1$s" class="widget %2$s">',
                             'after_widget' => "</li>\n",
                             'before_title' => '<h2 class="hl widgettitle">',
                             'after_title' => "</h2>\n",
                             ) );
// End Register Widgets

// Start Dynamic Copyright
function bns_dynamic_copyright() {
  /* Get all posts */
  $all_posts = get_posts( 'post_status=publish&order=ASC' );
  /* Get first post */
  $first_post = $all_posts[0];
  /* Get date of first post */
  $first_date = $first_post->post_date_gmt;
  $first_year = substr( $first_date, 0, 4 );
  if ( $first_year == '' ) {
    $first_year = date( Y );
  }

  /* Display common footer copyright notice */
  _e( 'Copyright &copy; ', 'desk-mess-mirrored' );
  /* Display first post year and current year */
  if ( $first_year == date( 'Y' ) ) {
  /* Only display current year if no posts in previous years */
    echo date( 'Y' );
  } else {
    echo $first_year . "-" . date( 'Y' );
  }
  /* Display blog name from 'General Settings' page */
  echo '  <strong>' . get_bloginfo( 'name' ) . '</strong>  ';
  _e( 'Todos os Direitos Reservados.', 'desk-mess-mirrored' );
}
// End Dynamic Copyright

// Start Theme Version
function bns_theme_version () {
  $theme_version = ''; /* Clear variable */
  /* Get details of the theme / child theme */
  $blog_css_url = get_stylesheet_directory() . '/style.css';
  $my_theme_data = get_theme_data( $blog_css_url );
  $parent_blog_css_url = get_template_directory() . '/style.css';
  $parent_theme_data = get_theme_data( $parent_blog_css_url );
  /* Create and append to string to be displayed */
  $theme_version .= '<br />' . $my_theme_data['Name'] . ' ' . $my_theme_data['Version'];
  if ( $blog_css_url != $parent_blog_css_url ) {
    $theme_version .= ' a child of the ' . $parent_theme_data['Name'] . ' ' . $parent_theme_data['Version'];
  }
  $theme_version .= ' ';
  /* Display string */
  echo $theme_version;
}
// End Theme Version

// Tell WordPress to run desk_mess_mirrored_setup() when the 'after_setup_theme' hook is run. */
add_action( 'after_setup_theme', 'desk_mess_mirrored_setup' );

if ( !function_exists( 'desk_mess_mirrored_setup' ) ):
  function desk_mess_mirrored_setup(){
    
    // This theme uses post thumbnails
    add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
    
    // Add default posts and comments RSS feed links to head
    add_theme_support( 'automatic-feed-links' );
    
    // Add theme support for editor-style
    add_editor_style();
    
    // This theme allows users to set a custom background
    add_custom_background();
    
    // Add wp_nav_menu() custom menu support
    add_theme_support( 'menus' );
    function dmm_nav_menu() {
      if ( function_exists( 'wp_nav_menu' ) )
        wp_nav_menu( array(
                           'theme_location' => 'top-menu',
                           'depth' => 1,
                           'fallback_cb' => 'dmm_list_pages'
                           ) );
      else
        dmm_list_pages();      
    }
    
    function dmm_list_pages() {
      if ( is_home() || is_front_page() ) {
        wp_list_pages( 'title_li=&depth=1' );
      } else { ?>
        <li><a href="<?php bloginfo( 'url' ); ?>"><?php _e( 'Home', 'desk-mess-mirrored' ) ?></a></li>
        <?php wp_list_pages( 'title_li=&depth=1' );
      }
    }
    
    add_action( 'init', 'register_dmm_menu' );
    function register_dmm_menu() {
      register_nav_menu( 'top-menu', __( 'Top Menu' ) );
    }
    // wp_nav_menu() end
    
    // Make theme available for translation
    // Translations can be filed in the /languages/ directory
    load_theme_textdomain( 'desk-mess-mirrored', TEMPLATEPATH . '/languages' );
    $locale = get_locale();
    $locale_file = TEMPLATEPATH . "/languages/$locale.php";
    if ( is_readable( $locale_file ) )
      require_once( $locale_file );
}
endif;

// Start BNS Modified Post - requires WordPress version 3.0 or greater
if ( version_compare( $wp_version, "2.999", ">" ) ) {
  function bns_modified_post(){
    /* If the post date and the last modified date are different display modified date */
    if ( get_the_date() <> get_the_modified_date() ) {
      echo '<div class="bns-modified-post">'; /* CSS wrapper for modified date details */
      echo 'Last modified by ' . get_the_modified_author() . ' on ' . get_the_modified_date();
      echo '</div><!-- .bns-modified-post -->';
    }
  }
}
// End BNS Modified Post

// Set the content width based on the theme's design and stylesheet, see #main-blog element in style.css
if ( ! isset( $content_width ) ) $content_width = 580;
?>
<?php /* Last Revision: 2010 Sept 02, v1.7.1 */ ?>